package top.ffhome.concurrent.beautiful.ch01;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

public class ThreadLocalTest {
    private static final Log log = LogFactory.get();

    static void print(String str) {
        log.info("{}:{}", str, localVariable.get());
        //localVariable.remove();
    }

    static ThreadLocal<String> localVariable = new ThreadLocal<>();

    public static void main(String[] args) throws InterruptedException {
        Thread threadOne = new Thread(() -> {
            localVariable.set("threadOne local variable");
            print("threadOne");
            log.info("threadOne remove after:{}", localVariable.get());
        });

        Thread threadTwo = new Thread(() -> {
            localVariable.set("threadTwo local variable");
            print("threadTwo");
            log.info("threadTwo remove after:{}", localVariable.get());
        });

        threadOne.start();
        threadTwo.start();
    }
}
